<?php

$posicao = (!isset($posicao) ? 1 : $posicao);
$div['class'] = (!isset($div['class']) ? '' : $div['class']);
$options = (!isset($options) ? array() : $options);

$_url = array('plugin' => 'banners', 'controller' => 'banners_has_paginas', 'action' => 'index');
$_named['named'] = array();
if (isset($this->request->params['pass'][0]) AND $this->request->params['plugin'] == 'paginas') {
    $_named['named']['BannersHasPagina.paginas_id'] = $this->request->params['pass'][0];
} else {
    $_named['named']['Banner.exibir_no_conteudo'] = 1;
}
$_named['named']['Banner.status'] = 1;
if ($posicao) {
    $_named['named']['Banner.banners_posicao_id'] = $posicao;
}
$_url['sort'] = 'created';
$_url['direction'] = 'desc';

$_banner = $this->requestAction($_url, $_named);
if (count($_banner) > 0) {
    foreach ($_banner as $key => $value) {
        if ($value['Banner']['url']) {
            $options['url'] = $value['Banner']['url'];
        }
        if ($value['Banner']['nome']) {
            $options['alt'] = $value['Banner']['nome'];
            $options['title'] = $value['Banner']['nome'];
        }
        if ($value['Banner']['target']) {
            $options['target'] = $value['Banner']['target'];
        }
        echo '<div class="' . $div['class'] . ' banners_simples">' . $this->Midia->get($value['Banner']['midia_id'], $options) . '</div>';
    }
}
?>